package cn.chinaunicom.sdsi.activiti.example.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.chinaunicom.sdsi.activiti.example.common.ActivitiCommon;
import cn.chinaunicom.sdsi.activiti.example.entity.Leave;
import cn.chinaunicom.sdsi.activiti.example.mapper.LeaveMapper;
import cn.chinaunicom.sdsi.activiti.example.service.LeaveService;

@Service
public class LeaveServiceImpl implements LeaveService{

	@Autowired
	private ActivitiCommon activitiCommon;
	@Autowired
	private LeaveMapper leaveMapper;
	
	@Override
	public List<Leave> queryLeave(Leave leave) {
		return null;
	}

	@Override
	public void save(Leave leave, String processDefinitionKey) {
		int id = leaveMapper.insert(leave);
		long day = leave.getlEndTime().getTime() - leave.getlStartTime().getTime();
		Map<String, Object> variables = new HashMap<>();
		variables.put("day", day/(1000*3600*24));
		activitiCommon.startProcess(processDefinitionKey, id+"", variables);
	}

}
